package com.joe.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class HistoryCalculator {

	public static final long ONE_DAY = 86400000;// 1*1000*60*60*24

	private HistoryCalculator() {

	}

	public static void main(String[] args) throws ParseException {
//		String dateStr1 = "2009-03-13 23:23:23";
//		String dateStr2 = "2009-03-10 1:01:01";
//		String dateStr3 = "2008-02-10 12:00:00";
//		Date date1 = getDate(dateStr1);
//		System.out.println("date1 earlier than today? "
//				+ earlierThanToday(date1));
		compare();
	}

	public static Date getDate(String dateStr) {
		Date date = null;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			date = format.parse(dateStr);
			System.out.println(date);
		} catch (Exception ee) {
			ee.printStackTrace();
		}
		return date;
	}

	public static boolean earlierThanToday(Date date) {
		boolean earlierThanToday = false;
		long theOtherDay = date.getTime() % ONE_DAY;
		System.out.println("the other day: " + theOtherDay);
		System.out.println("the other day -> per minutes: "+(theOtherDay/1000/60.0));
		Date cur = new Date();
		long today = cur.getTime() % ONE_DAY;
		System.out.println("today: " + today);
		System.out.println("today -> per minutes: "+(today/1000/60.0/60));
		if (theOtherDay < today) {
			earlierThanToday = true;
		}
		return earlierThanToday;
	}
	public static void compare() throws ParseException{
		long now = new Date().getTime();
		long rightTodayBegin = (new SimpleDateFormat("yyyy-MM-dd")).parse("2009-03-14").getTime();
		System.out.println("now: "+now+"\n rightTodayBegin: "+rightTodayBegin);
		System.out.println("(now-rightTodayBegin)/1000/60.0: "+(now-rightTodayBegin)/1000/60.0+" seconds.");
		long anotherWay = new Date().getTime() % ONE_DAY;
		System.out.println((anotherWay)/1000/60.0);
	}
}
